package br.unidocs.modelo.entidade;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * The persistent class for the noticias database table.
 * 
 */

@NamedQueries({
		@NamedQuery(name = "listaNoticias", query = "select n from Noticia n"),
		@NamedQuery(name = "listaNoticiasPorDataDesc", query = "select n from Noticia n order by n.dataCriacao desc") })
@Entity
@Table(name = "noticias")
public class Noticia implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(name = "NOTICIAS_ID_GENERATOR", sequenceName = "SEQ_ID_NOT", allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "NOTICIAS_ID_GENERATOR")
	@Column(name = "id_not")
	private Integer id;

	@Temporal(TemporalType.DATE)
	@Column(name = "dt_criacao_not")
	private Date dataCriacao;

	@Column(name = "texto_not")
	private String texto;

	// Comparadores de notícia
	public static Comparator<Noticia> COMPARADOR_POR_ID = new Comparator<Noticia>() {
		@Override
		public int compare(Noticia o1, Noticia o2) {
			return o1.getId().compareTo(o2.getId());
		}
	};

	public static Comparator<Noticia> COMPARADOR_POR_ID_DESC = new Comparator<Noticia>() {
		@Override
		public int compare(Noticia o1, Noticia o2) {
			return o1.getId().compareTo(o2.getId()) * -1;
		}
	};

	public static Comparator<Noticia> COMPARADOR_POR_DATA = new Comparator<Noticia>() {
		@Override
		public int compare(Noticia o1, Noticia o2) {
			return o1.getDataCriacao().compareTo(o2.getDataCriacao());
		}
	};

	// bi-directional many-to-one association to Usuario
	@ManyToOne
	@JoinColumn(name = "id_usu_not")
	private Admin admin;

	public Admin getAdmin() {
		return admin;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

	public Noticia() {
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Date getDataCriacao() {
		return this.dataCriacao;
	}

	public void setDataCriacao(Date dataCriacao) {
		this.dataCriacao = dataCriacao;
	}

	public String getTexto() {
		return this.texto;
	}

	public void setTexto(String texto) {
		this.texto = texto;
	}

}